/*
 * Copyright 2011 Jin Kwon <jinahya at gmail.com>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package com.googlecode.flac4j.format.metadata;


import com.googlecode.jinahya.util.BitAccessible;

import java.nio.charset.Charset;

import javax.xml.bind.annotation.XmlTransient;


/**
 *
 * @author Jin Kwon <jinahya at gmail.com>
 */
public abstract class Data implements BitAccessible {


    static final Charset ASCII = Charset.forName("US-ASCII");


    static final Charset UTF_8 = Charset.forName("UTF-8");


    /**
     * Returns data length in bytes.
     *
     * @return data length.
     */
    public abstract int getLengthInBytes();


    /**
     * Returns block type of this data.
     *
     * @return block type
     */
    public abstract BlockType getBlockType();


    /**
     * Returns parent block.
     *
     * @return parent block.
     */
    public final Block getBlock() {
        return block;
    }


    /**
     * Sets parent block.
     *
     * @param block parent block.
     */
    public final void setBlock(final Block block) {

        if (block == null) {
            throw new NullPointerException("null block");
        }

        this.block = block;
    }


    /**
     * Returns block header.
     *
     * @return block header.
     */
    protected final Header getHeader() {
        return block.getHeader();
    }


    /*
    @XmlTransient
    private final BlockType blockType;
     */
    @XmlTransient
    private Block block;


}

